package pkg.drowne.org;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class Intro extends Activity implements OnClickListener {
		
		ImageButton loginButton, registerButton;
		
		// Preference file
		public static final String PREF_FILE = "pf2";
		private SharedPreferences preferences;
		
		
	    /** Called when the activity is first created. */
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        getWindow().setFlags(
	        WindowManager.LayoutParams.FLAG_FULLSCREEN,
	        WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        setContentView(R.layout.intro);
	        
	        registerViews();
	        setupOnClickListeners();
	        
	        if (checkifFirstTime()){
	        	Utils.showToastShort(getBaseContext(), "You need to register or login to play HASP!");	
	        }
	        else {
	        	Log.d("NotFirstTime","NOT!!!");
	        	Intent loginIntent = new Intent(this, login.class);
	    		startActivity(loginIntent);
	        }
	        
	    }
	    
	    private void registerViews() {
			
	    	loginButton 	= (ImageButton)this.findViewById(R.id.login_button);
	    	registerButton 	= (ImageButton)this.findViewById(R.id.register_button);
	    	
		}

		public void setupOnClickListeners() {
	        
			loginButton.setOnClickListener(this);
			registerButton.setOnClickListener(this);
	    }
	    
	    public void onClick(View V) {
	    	
	    	switch(V.getId()) {
	    	
	    	case R.id.login_button:
	    		Intent loginIntent = new Intent(this, login.class);
	    		startActivity(loginIntent);
	    		break;
	    		
	    	case R.id.register_button:
	    		Intent registerIntent = new Intent(this, register.class);
	    		startActivity(registerIntent);
	    		break;

	    	}

	    }
	    
	    private boolean checkifFirstTime() {
	    	
	    	// check for the saved preferences  
	        // get the preferences file ready
	    	//preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
			
	    	preferences = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
			
			boolean load = preferences.getBoolean("first", true);
			
			Log.d("checkifFirstTime", load+"");
			
			return load;
			
		}
}
